package yf.dao;


import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.io.Resources;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.SQLException;

//执行sql文件语句
public class ExcutSqlFile {
    public static Connection conn=null;
    public static void excute(String fileName) throws SQLException, IOException, ClassNotFoundException {
      if(!"".equals(fileName)){
          conn = DBDPConnection.getDPConnection();
          ScriptRunner runner = new ScriptRunner(conn);
          Resources.setCharset(Charset.forName("UTF-8"));
          runner.setDelimiter(";"); //语句结束符号设置
          runner.setLogWriter(null);//设置是否输出日志

          //案例执行前的参数维护
          runner.runScript(Resources.getResourceAsReader("./sql/"+ fileName +".sql"));
          runner.closeConnection();
          conn.close();
      }
    }
}
